class ApplicationController < ActionController::API

	before_action :set_csrf_cookie, :require_login
	include ActionController::Cookies
	include ActionController::RequestForgeryProtection

	# skip_before_action :require_user, only: [:register, :signin]
	helper_method :current_user

	def current_user
	       @current_user ||= session[:user_id] && User.find(session[:user_id])
	end
	# helper_method :require_user
	def require_login
	       render json: {status:'error', type:'account', currentAuthority:'guest', info:{error:'login_required!'}} unless current_user
	end

	private  
	def set_csrf_cookie
	   cookies["CSRF-TOKEN"] = form_authenticity_token
	end
end
